import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";

/**
 * 查询学分认定开关设置
 */
export function getSetting() {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/getSetting',
        method: 'get'
    });
}

/**
 * 认定学分设置保存
 * @param {*} data
 */
export function cfgSetting(data) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/cfgSetting',
        method: 'post',
        data
    });
}

/**
 * 认定学分申请（校内）查询列表
 */
export function getCreditAffirmList(data) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/getCreditAffirmList',
        method: 'post',
        data
    });
}

/**
 * 根据传入的id获取申请信息
 * @param {*} id
 */
export function findCreditAffirmById(id = '') {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/findCreditAffirmById?id=' +
            id,
        method: 'get'
    });
}

export function getStudentIdByPaperwork(id = '') {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getStudentIdByPaperwork?studentId=' +
            id,
        method: 'get'
    });
}

/**
 * 查询课程信息
 * @param {*} 课程代码
 */
export function selectStudentScoreData(data) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/selectStudentScoreData?studentId=' + data,
        method: 'get'
    });
}

/**
 * 查询学分认定未审核列表
 * @param {*} data
 */
export function getCreditAffirmAuditList(data) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getCreditAffirmAuditList',
        method: 'post',
        data
    });
}

/**
 * 查询学分认定指定审核未审核列表
 * @param {*} data
 */
export function getAppointAuditDataList(data) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getAppointAuditDataList',
        method: 'post',
        data
    });
}

/**
 * 查询学分认定已审核列表
 * @param {*} data
 */
export function getCreditAffirmAuditedList(data) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getCreditAffirmAuditedList',
        method: 'post',
        data
    });
}

/**
 * 根据学号和课程代码查询成绩信息
 * @param {*} student
 * @param {*} courseCode
 */
export function findScoreByStuIdAndCurCode(student, courseCode) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/selectStudentScoreData?studentId=' +
            student +
            '&courseCode=' +
            courseCode,
        method: 'get'
    });
}

/**
 * 提交学分认定申请
 * @param {*} data
 */
export function applyCreditAffirm(data) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/applyCreditAffirm',
        method: 'post',
        data
    });
}

/**
 * 根据学生ID获取学生信息
 * @param {*} id
 */
export function getStuInfoByStudentId(id) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getStuInfoByStudentId?studentId=' +
            id,
        method: 'get'
    });
}

/**
 * 查询工作流
 * @param {*} id
 */
export function findApprovalInfo(id) {
    return fetch({
        url: '/api/scoremanagementservice/studentScoreChange/querySocreChangeFlowInfo',
        method: 'GET',
        params: {
            no: id
        }
    });
}

/**
 * 取消指定审核人
 * @param {*} ids
 */
export function cancelAuditTeacher(ids) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/cancelAuditTeacher',
        method: 'GET',
        params: {
            ids: ids
        }
    });
}

/**
 * 指定审核人
 * @param {*} data
 */
export function setAuditTeacher(data = {}) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/setAuditTeacher',
        method: 'post',
        data
    });
}

/**
 * 是否是申请时间
 */
export function isCanApply() {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/isCanApply',
        method: 'GET'
    });
}

/**
 * 批量通过
 * @param {*} data
 */
export function allPassFunc(data = {}) {
    return fetch({
        url: '/api/workflow/approval/through/batch',
        method: 'post',
        data
    });
}

export function updateAllAuditStatus(data) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/updateAllAuditStatus',
        method: 'post',
        data
    });
}

/**
 * 撤回操作
 * @param {*} data
 */
export function recall(data = {}) {
    return fetch({
        url: '/api/workflow/approval/recall',
        method: 'post',
        data
    });
}

/**
 * 更新撤回后状态
 * @param {*} data
 */
export function updateAffirmApplyStatus(data = {}) {
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/updateAffirmApplyStatus',
        method: 'post',
        data
    });
}

/**
 * 根据id获取认定成绩信息
 * @param {*} id
 */
export function getDstCourseList(id) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getDstCourseList?studentId=' +
            id,
        method: 'GET'
    });
}

/**
 * 查询课程信息
 * @param {*} 课程代码
 */
export function getCourseListByCodeOrName(data) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/getCourseListByCodeOrName',
        method: 'post',
        data
    });
}


/**
 * 根据课程代码获取课程信息
 */
export function findOpenCourseByCourseCode(id) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/findOpenCourseByCourseCode?courseCode=' +
            id,
        method: 'GET'
    });
}

/**
 * 判断是开课学院还是行政学院
 * @param {*} id
 */
export function updateOneAuditStatus(id, dstScore) {
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm/updateOneAuditStatus?auditCode=' +
            id +
            '&dstScore=' +
            dstScore,
        method: 'GET'
    })
}

export function updateCreditAffirmStatus(data){
    return fetch({
        url:
            '/api/scoremanagementservice/creditaffirm//updateCreditAffirmStatus',
        method: 'post',
        data
    });
}

export function exportList(data){
    return fetch({
        url:'/api/scoremanagementservice/creditaffirm/exportAffirmStudentExcel',
        method: 'post',
        responseType: 'blob',
        data
    }).then(res => {
        UTILS.downloadFile(res, data.releaseType == 0 ? '学分认定待审核学生表.xlsx' : '学分认定已审核学生表.xlsx' , 'application/vnd.ms-excel;charset=utf-8')
    })
}

export function updateScoreChangeFlowContent(data){
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/updateScoreChangeFlowContent',
        method: 'post',
        data
    })
}

export function queryNeedApprovalTaskNoList(data){
    return fetch({
        url: '/api/scoremanagementservice/creditaffirm/queryNeedApprovalTaskNoList',
        method: 'post',
        data
    })
}
/**
 * 查询学分认定未审核列表是否已有成绩
 * @param {*} data
 */
export function queryStudentScoreList(data) {
           return fetch({
               url: '/api/scoremanagementservice/creditaffirm/queryStudentScoreList',
               method: 'post',
               data
           })
       }